﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SiteFox.Business.Manager
{
    public static class Group
    {
        public static List<Model.Group> GetAll()
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.Group select c;
            return _Query.ToList();
        }
        public static Model.Group GetById(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.Group where c.ID == _ID select c;
            return _Query.SingleOrDefault();
        }
        public static void Create(Model.Group _Group)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            _Entities.AddToGroup(_Group);
            _Entities.SaveChanges();
        }
        public static void Edit(Model.Group _Group)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.Group where c.ID == _Group.ID select c;
            var __Group = _Query.Single();
            __Group.Name = _Group.Name;
            __Group.Description = _Group.Description;
            _Entities.SaveChanges();
        }
        public static void Delete(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.Group where c.ID == _ID select c;
            var _Group = _Query.SingleOrDefault();
            _Entities.Group.DeleteObject(_Group);
            _Entities.SaveChanges();
        }
    }
}
